package com.sz.stock.commons;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {
    public static String encoderByMD5(String str) throws NoSuchAlgorithmException {
        /* 改用适用于PHP的MD5加密，PHP中使用md5()方法加密得到的是32位的加密代码 */
        MessageDigest digest = MessageDigest.getInstance("md5");
        byte[] result = digest.digest(str.getBytes());
        StringBuilder buffer = new StringBuilder();
        for(byte b:result) {
            int number = b & 0xff;
            String s = Integer.toHexString(number);
            if(s.length() == 1) {
                buffer.append("0");
            }
            buffer.append(s);
        }
        return buffer.toString();
    }
}
